package controler;


import java.io.Serializable;
import java.util.Collection;


import ema.tpjee.banking.facade.SessionFacade;
import ema.tpjee.banking.model.Bank;



public class BankControler implements Serializable{
	

	private static final long serialVersionUID = -1645348478746136298L;

	private SessionFacade sessionFacade;

	
	public BankControler() {
		super();
		System.out.println("creating BankControler");
	}

	public Collection<Bank> getList() {
		return sessionFacade.getBankDao().getList();
	}

	public void setList(Collection<Bank> dumm) {
		
	}

	public void add(Bank b) {
		sessionFacade.getBankDao().add(b);
	}
	
	public String cancel() {
		System.out.println("action "+this.getClass().getName()+" cancel()");
		return "list";
	}
	
	public String save(){
		System.out.println("action "+this.getClass().getName()+" save()");
		//implicit commit by lifecycle, validators will work
		return "list";
	}
	
	public String delete(){
		System.out.println("action "+this.getClass().getName()+" delete()");	
		sessionFacade.deleteBank();
		return "list";
	}	
	
	public String edit() {
		System.out.println("action "+this.getClass().getName()+" edit()");
		int bankId=sessionFacade.getCurrentBank().getId();
		System.out.println(bankId);
		return "edit";
	}
	
	public String create() {
		System.out.println("action "+this.getClass().getName()+" create()");
		sessionFacade.newBank();
		return "edit";
	}

	public String showCustomers() {
		System.out.println("action "+this.getClass().getName()+" showCustomers()");
		return "customers";
	}

	public String next() {
		System.out.println("action "+this.getClass().getName()+" next()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().next((sessionFacade.getCurrentBank())));
		return "edit";
	}
	
	public String prior() {
		System.out.println("action "+this.getClass().getName()+" prior()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().prior((sessionFacade.getCurrentBank())));
		return "edit";
	}
	public String copy() {
		System.out.println("action "+this.getClass().getName()+" copy()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().clone((sessionFacade.getCurrentBank())));
		return "list";
	}
	
	public String list() {
		System.out.println("action " + this.getClass().getName() + " list()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "list";
	}
	
	public String foobar() {
		System.out.println("action "+this.getClass().getName()+" foobar()");
		return "edit";
	}
		
	
	public void setSessionFacade(SessionFacade sf) {
		this.sessionFacade=sf;	
		System.out.println(this.getClass().getName()+" setSessionFacade");
	}


}
